<template>
    <view style="height: 100%">
        <ul class="db">
            <li class="h48 df ac bbf1">
                <p class="w75 f14 c28">公司名称</p>
                <input class="f1 f14 c25" :value="company" @input="onInput" :data-type="0" placeholder="请填写公司名称" placeholder-class="cc" />
            </li>
            <li class="h48 df ac bbf1">
                <p class="w75 f14 c28">产品范围</p>
                <input class="f1 f14 c25" :value="goods_range" @input="onInput" :data-type="1" placeholder="请填写产品范围" placeholder-class="cc" />
            </li>
            <li class="h48 df ac bbf1">
                <p class="w75 f14 c28">公司地点</p>
                <input class="f1 f14 c25" :value="address" @input="onInput" :data-type="2" placeholder="请填写公司地点" placeholder-class="cc" />
            </li>
            <li class="h48 df ac bbf1">
                <p class="w75 f14 c28">联系人</p>
                <input class="f1 f14 c25" :value="username" @input="onInput" :data-type="3" placeholder="请填写联系人" placeholder-class="cc" />
            </li>
            <li class="h48 df ac bbf1">
                <p class="w75 f14 c28">联系电话</p>
                <input class="f1 f14 c25" :value="mobile" @input="onInput" :data-type="4" type="number" placeholder="请填写联系电话" placeholder-class="cc" />
            </li>
        </ul>

        <view class="mt30">
            <button class="sub" @tap="onSub">提交</button>
        </view>
    </view>
</template>

<script>
const http = require('../../utils/http');
export default {
    data() {
        return {
            company: '',
            goods_range: '',
            address: '',
            username: '',
            mobile: ''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {},
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    methods: {
        onSub() {
            let data = {
                company: this.company,
                goods_range: this.goods_range,
                address: this.address,
                username: this.username,
                mobile: this.mobile
            };
            http.request('user/applySupplierAdd', data)
                .then((res) => {
                    setTimeout(() => {
                        uni.reLaunch({
                            url: '/pages/demand/subSuccess?type=2'
                        });
                    }, 1000);
                })
                .catch((res) => {
                    uni.showToast({
                        title: res.message,
                        icon: 'none'
                    });
                });
        },

        onInput(e) {
            let val = e.detail.value;
            let type = e.currentTarget.dataset.type;
            switch (type) {
                case 0:
                    this.setData({
                        company: val
                    });
                    break;
                case 1:
                    this.setData({
                        goods_range: val
                    });
                    break;
                case 2:
                    this.setData({
                        address: val
                    });
                    break;
                case 3:
                    this.setData({
                        username: val
                    });
                    break;
                case 4:
                    this.setData({
                        mobile: val
                    });
                    break;
            }
        }
    }
};
</script>
<style>
@import './supplier.css';
</style>
